<template>
  <el-row type="flex" class="row-bg" justify="center" v-title data-title="登陆-后台管理系统">
    <el-col :xl="6" :lg="7">
      <div class="login-form">
        <h2>欢迎来到与时网管理系统</h2>
        <br>
        <p>让生活方式方式变得更简单！</p>
      </div>
    </el-col>
    <el-col :span="1">
      <el-divider direction="vertical"></el-divider>
    </el-col>
    <el-col :xl="6" :lg="7">
      <el-form label-position="right" :rules="rules" label-width="80px" :model="loginForm" ref="loginForm">
        <el-form-item label="用户名" prop="username" style="width: 380px;">
          <el-input placeholder="请输入用户名" v-model="loginForm.username"></el-input>
        </el-form-item>
        <el-form-item label="密码" prop="password" style="width: 380px;">
          <el-input placeholder="请输入密码" type="password" v-model="loginForm.password"></el-input>
        </el-form-item>

        <el-form-item>
          <el-button style=" width: 200px;" type="primary" @click="submitForm('loginForm')">登 录</el-button>
        </el-form-item>
      </el-form>
    </el-col>
  </el-row>
</template>

<script>

import qs from 'qs'

export default {
  name: "admin",

  data() {
    return {
      loginForm: {
        username: '',
        password: '',
      },
      rules: {
        username: [
          {required: true, message: '请输入用户名', trigger: 'blur'},
		  { min: 3, max: 15, message: '长度在 3 到 15 个字符', trigger: 'blur' }
        ],
        password: [
          {required: true, message: '请输入密码', trigger: 'blur'}
        ],
      },
      captchaImg: ''
    }
  },
  methods: {
    submitForm(formName) {
      this.$refs[formName].validate((valid) => {
        if (valid) {
		//const _this = this
          this.$axios.post('/admin' , this.loginForm).then(res => {
            
			const jwt = res.headers['authorization']
			const adminInfo = res.data.data

            // 将jwt存储到应用store中
            this.$store.commit("SET_TOKEN", jwt)
			this.$store.commit("SET_ADMININFO", adminInfo)
			// 获取
			// console.log(_this.$store.getters.getAdmin)
            this.$message({
              message: '您好,管理员',
              type: 'success'
            })
            this.$router.push("/adminHome")
          })
        } else {
          console.log('error submit!!');
          return false;
        }
      });
    },
	//重置按钮
    resetForm(formName) {
      this.$refs[formName].resetFields();
    },
  },

}
</script>

<style scoped>
.el-col {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100%;
  text-align: center;
}

.el-row {
  height: 100%;
  background-color: #fafafa;
}

.el-divider {
  height: 200px;
}

.captchaImg {
  float: left;
  margin-left: 8px;
  border-radius: 4px;
}
</style>
